<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){
    	
    	//查询赋值分类
    	$category = M('Category')->where(array('status'=>1,'type'=>1))->select();
    	$this->assign('category',$category);

    	//查询赋值友链
    	$url_list = M('Url')->where(array('status'=>1,'type'=>1))->select();
    	$this->assign('url_list',$url_list);

    	//dump($url_list);
        $this->display();
    }

    public function recommend(){

    	$attachment = M('Attachment');

		$count      = $attachment->where(array('status'=>1,'display'=>1))->count();// 查询满足要求的总记录数
		import('Common.Util.Page');
		$Page 		= new \Page($count,20);
		//$Page       = new \Think\Page($count,2);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性


    	$att = $attachment->where(array('status'=>1,'display'=>1))->order('sort desc,view desc')->limit($Page->firstRow.','.$Page->listRows)->select();

    	$comment = M('Comment');
    	foreach ($att as $key => $value) {
    		$att[$key]['comments'] = $comment->where("aid=".$value['aid'])->count();
    	}

		$this->assign('page',$show);// 赋值分页输出
		//dump($show);
    	//dump($attachment);
    	$this->assign('attachment',$att);

    	//查询分类
    	$category = M('Category')->where(array('status'=>1,'type'=>1))->limit(20)->select();
    	foreach ($category as $key => $value) {
    		$category[$key]['categorys'] = $attachment->where("category=".$value['cid'])->count();
    	}
    	$this->assign('category',$category);

    	//查询标签
    	$tags = M('Tags')->where(array('status'=>'1'))->limit(20)->select();
    	$this->assign('tags',$tags);

    	$this->meta_title = "推荐";
        $this->display();
    }
    public function che(){
    	echo 1;
    }
}